home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / 80x0393.zip / LOCKKEY.TXT < prev    next >
Text File  |  1993-03-30  |  4KB  |  76 lines

  1. By: Emil Gilliam
  2. Re: lockout keyboard
  3. ------------------------------------------------------------------------
  4.  
  5.    Locking out the keyboard simply by redirecting int 9 to an IRET won't 
  6. do it.  The reason is that at the end of every interrupt handler (for an 
  7. IRQ,  not for software-generated interrupts like int 21h  or  processor-
  8. generated  interrupts like divide-by-zero int 0) you must send the  byte 
  9. 20h to I/O port 20h.  You can do it with the instructions MOV AL,20h and 
  10. OUT  20h,AL.   What they do is send  a  "non-specific  end-of-interrupt" 
  11. (EOI) to the 8259 programmable interrupt controller chip.
  12.  
  13.    The 8259 chip (which on newer computers usually isn't a separate chip 
  14. but  part  of some chip that contains other things)  is  what  generates 
  15. IRQ's.  It's connected to all of the hardware devices that can  generate 
  16. interrupts  (except  for  memory parity error  which  is  another  thing 
  17. entirely, which doesn't even use IRQ's but is connected straight to  the 
  18. processor's  NMI  pin and generates interrupt 2).  When one of  its  IRQ 
  19. pins  (there's  one for each IRQ that can be generated)  goes  high,  it 
  20. figures  out  what the interrupt number is.  How does it know  what  the 
  21. interrupt  number is?  (to send to the processor on the data  bus  while 
  22. making  the processor's IRQ pin go high) When the computer is booted  up 
  23. the BIOS sends a setup command to the 8259 that tells it to add 8 to the 
  24. number of an IRQ line that goes high to get the interrupt number to send 
  25. to the processor.  (The keyboard is connected to the 8259's IRQ1 pin, so 
  26. that's why it generates interrupt 9.)
  27.  
  28.    However,  the  8259  is designed not to let  one  hardware  interrupt 
  29. interrupt  another hardware interrupt.  For example, if the computer  is 
  30. in  the middle of processing interrupt 8 (the timer tick)  and  keyboard 
  31. signals  an  interrupt  to the 8259, int 9 won't  be  called  until  the 
  32. interrupt  8 handler is done. How does the 8259 know when the  processor 
  33. is  executing an interrupt handler?  When an interrupt is generated  the 
  34. 8259  assumes  that the interrupt handler is being  executed  until  the 
  35. software  sends it an end-of-interrupt command (sending the byte 20h  to 
  36. I/O port 20h), and the end-of-interrupt command lets other interrupts be 
  37. processed.
  38.  
  39.    What happens in your program is that when int 9 is generated, it just 
  40. IRETs,  so no further IRQs can be generated (timer tick or  keyboard  or 
  41. anything like that).  Even when the int 9 vector is stored, the program
  42. mable  interrupt  controller won't allow an interrupt to  interrupt  the 
  43. processor.  (I think that's how it works, maybe it just don't let  other 
  44. IRQ1's  interrupt  the  processor while other IRQ's  can  interrupt  the 
  45. processor.)
  46.  
  47.   One workaround is to have your temporary int 9 handler look like this:
  48.  
  49. push ax                 ;Save AX
  50. mov  al,20h             ;Send a non-specific EOI to the PIC (programmable
  51. out  20h,al             ; interrupt controller) so that other interrupts 
  52.                         ; can be generated
  53. pop  ax                 ;Restore AX
  54. iret                    ;Return from the interrupt
  55.  
  56. HOWEVER...  (and I'm sorry if I've wasted your time up to this point...) 
  57. there's  a much easier way to disable the keyboard  without  revectoring 
  58. interrupt 9.
  59.  
  60. TO DISABLE THE KEYBOARD...    in  al,21h
  61.                               or  al,00000010b
  62.                               out 21h,al
  63.  
  64. TO ENABLE THE KEYBOARD...     in  al,21h
  65.                               and al,11111101b
  66.                               out 21h,al
  67.  
  68. I/O port 21h is the programmable interrupt controller's "mask" register.  
  69. It  controls  which  IRQ's the PIC will allow and  which  ones  it  will 
  70. ignore.  Bit 0 is for IRQ0, bit 1 is for IRQ1 (the keyboard), and so on.  
  71. Setting  a bit disables that IRQ, clearing it enables it.  When you  get 
  72. whatever's in port 21h and set bit 1 and write that back it will disable 
  73. the keyboard interrupt.
  74.  
  75.                                                         Emil Gilliam
  76.